﻿using BuyWithoutLoseMoney.Core.Models;
using BuyWithoutLoseMoney.Core.Repositories;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Linq;

namespace BuyWithoutLose.Areas.Admin.Controllers
{
    [Area("Admin")]
    public class HomeController : Controller
    {
        private readonly IRepository<Comment, int> _commentRepository;
        private readonly IRepository<Order, int> _orderRepository;

        private readonly IRepository<User, int> _userRepository;
        private readonly IRepository<LoginUserRole, int> _loginUserRoleRepository;

        public HomeController(IRepository<Comment, int> commentRepository
            , IRepository<User, int> userRepository
            , IRepository<LoginUserRole, int> loginUserRoleRepository
            , IRepository<Order, int> orderRepository)
        {
            _commentRepository = commentRepository;
            _userRepository = userRepository;
            _loginUserRoleRepository = loginUserRoleRepository;
            _orderRepository = orderRepository;
        }

        /// <summary>
        /// 后台首页
        /// </summary>
        /// <returns></returns>

        public IActionResult Index()
        {
            var comment= _commentRepository.GetAllList();
            ViewBag.Comment = comment;
            var user = _userRepository.GetAllList();
            ViewBag.User = user;
            var order = _orderRepository.GetAllList().Where(x=>x.CreateTime> DateTime.Now.Date);
            double sum = 0;
            foreach (var item in order)
            {
                sum += item.TotalMoney;
            }
            ViewBag.OrderTotalMoney = sum;
            return View();
        }
        public IActionResult Layout()
        {
            return View();
        }
    }
}
